package com.credithc.customers.base.mapper;

import com.credithc.baseserv.core.mapper.BsBaseMapper;
import com.credithc.customers.base.po.CustomerManageStatisticPo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Title:
 * @Author: Denghx
 * @Date: 2019/4/15 17:55
 * @Description: com.credithc.customers.base.mapper
 * @Version: V1.0.0
 */
@Mapper
@Repository
public interface CustomerManageStatisticMapper extends BsBaseMapper<CustomerManageStatisticPo> {

    @Select("select sub_system_sign as subSystemSign,#{yesterDay} AS date,count(1) as sum,CURRENT_TIMESTAMP() as createTime from cust_manage_info where date <#{date} group by sub_system_sign union all select 'ALL' AS subSystemSign,#{yesterDay} AS date,count(1) as sum,CURRENT_TIMESTAMP() as createTime from cust_id_info where customer_property='1' and create_time <#{date}"
    )
    List<CustomerManageStatisticPo> getManageInit(@Param("date") String date, @Param("yesterDay") String yesterDay);

    @Select("SELECT sum FROM cust_manage_statistic WHERE date = #{date} AND sub_system_sign = #{subSystemSign}")
    String getPastSum(@Param("subSystemSign") String subSystemSign, @Param("date") String date);

    @Select("SELECT count(1) FROM cust_id_info WHERE create_time BETWEEN #{endDate} AND #{createTimeEnd} ")
    int getTodaySumByAll(@Param("subSystemSign") String subSystemSign, @Param("createTimeEnd") String createTimeEnd, @Param("endDate") String endDate);

    @Select("SELECT count(1) FROM cust_manage_info WHERE date = #{endDate} AND sub_system_sign = #{subSystemSign} ")
    int getTodaySumBySys(@Param("subSystemSign") String subSystemSign, @Param("endDate") String endDate);
}
